'''
Created on 12/10/2011

@author: Oswaldo
'''
import unittest
from LogManager import LogManager

class TestLogManager(unittest.TestCase):

    def setUp(self):
        self.logManager = LogManager()
        
    def testCreateLogManager(self):
        self.assertIsInstance(self.logManager, LogManager, "Error creating a new LogManager")
    
    def testReadConf(self):
        self.assert_(self.logManager.readConf(), "Failed reading configuration file")
    
    def testGetSettings(self):
        self.assertEqual(self.logManager.getFormat(), "Long", "Failed getting Format")
        self.assertEqual(self.logManager.getLogLevel(), "DEBUG", "Failed getting Loglevel")
        self.assertEqual(self.logManager.getTarget(), "xml", "Failed getting Target")
        self.assertEqual(self.logManager.getTimeFormat(), "Full", "Failed getting TimeFormat")
        self.assertEqual(self.logManager.getEverything(), ["Long","xml","Full","DEBUG"] , "Failed getting All Settings")
    
    def testSetSettings(self):
        self.assertEqual(self.logManager.setFormat("Short"), None, "Failed setting Format")
        self.assertEqual(self.logManager.setLogLevel("NORMAL"), None, "Failed setting Loglevel")
        self.assertEqual(self.logManager.setTarget("csv"), None, "Failed setting Target")
        self.assertEqual(self.logManager.setTimeFormat("LongTime"), None, "Failed setting TimeFormat")
        self.assertEqual(self.logManager.getEverything(), ["Short","csv","LongTime","NORMAL"] , "Failed getting new set Settings")
        
    def testSaveConf(self):
        self.logManager.setFormat("Short")
        self.logManager.setLogLevel("NORMAL")
        self.logManager.setTarget("csv")
        self.logManager.setTimeFormat("LongTime")
        self.assert_(self.logManager.saveConf(), "Error saving conf file")
        self.logManager = LogManager()
        self.assertEqual(self.logManager.getFormat(), "Short", "Failed getting Format")
        self.assertEqual(self.logManager.getLogLevel(), "NORMAL", "Failed getting Loglevel")
        self.assertEqual(self.logManager.getTarget(), "csv", "Failed getting Target")
        self.assertEqual(self.logManager.getTimeFormat(), "LongTime", "Failed getting TimeFormat")
    
    def tearDown(self):
        self.logManager.setFormat("Long")
        self.logManager.setLogLevel("DEBUG")
        self.logManager.setTarget("xml")
        self.logManager.setTimeFormat("Full")
        self.assert_(self.logManager.saveConf(), "Error saving conf file for restoring")
        
if __name__ == "__main__":
    unittest.main()